package com.huaboot.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.huaboot.commont.core.BaseResponse;
import com.huaboot.commont.core.ResultUtils;
import com.huaboot.system.convert.GenTestStudentConvert;
import com.huaboot.system.entity.GenTestStudentEntity;
import com.huaboot.system.service.GenTestStudentService;
import com.huaboot.system.query.GenTestStudentQuery;
import com.huaboot.system.vo.GenTestStudentVO;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.huaboot.commont.page.PageResult;
import java.util.List;

/**
* 测试2
*
* @author ff 1
* @since 1.0.0 2023-08-22
*/
@RestController
@RequestMapping("system/student")
@Tag(name = "测试学生模块")
@AllArgsConstructor
public class GenTestStudentController {
    private final GenTestStudentService genTestStudentService;

    @GetMapping("page")
    @Operation(summary = "分页")
   // @PreAuthorize("hasAuthority('system:student:page')")
    public BaseResponse<PageResult<GenTestStudentVO>> page(GenTestStudentQuery query){
        return ResultUtils.success(genTestStudentService.page(query));
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
   // @PreAuthorize("hasAuthority('system:student:info')")
    public BaseResponse<GenTestStudentVO> get(@PathVariable("id") Long id){
        GenTestStudentEntity entity = genTestStudentService.getById(id);
        GenTestStudentVO convert = GenTestStudentConvert.INSTANCE.convert(entity);
        convert.setSex(1);
        return ResultUtils.success(convert);
    }

    @PostMapping
    @Operation(summary = "保存")
   // @PreAuthorize("hasAuthority('system:student:save')")
    public BaseResponse<?> save(@RequestBody GenTestStudentVO vo){
        genTestStudentService.save(vo);

        return ResultUtils.success("新增成功");
    }

    @PutMapping
    @Operation(summary = "修改")
   // @PreAuthorize("hasAuthority('system:student:update')")
    public BaseResponse<?> update(@RequestBody  GenTestStudentVO vo){
        genTestStudentService.update(vo);

        return ResultUtils.success("修改成功");
    }

    @DeleteMapping
    @Operation(summary = "删除")
   // @PreAuthorize("hasAuthority('system:student:delete')")
    public BaseResponse<?> delete(@RequestBody List<Long> idList){
        genTestStudentService.delete(idList);

        return ResultUtils.success("删除成功");
    }
}
